﻿using UnityEngine;
using System.Collections;

public class MonkeyController : MonoBehaviour {

    public Joystick joystick;
    public float Sensivity = 0.1f;
    public Character Controller;

    public Button ButtonJump;
    public Button ButtonFire;

	void Start () 
    {
        ButtonJump.ButtonClick += ButtonJump_ButtonClick;
        ButtonFire.ButtonClick += ButtonFire_ButtonClick;
	}

    void ButtonFire_ButtonClick()
    {
        Controller.Shoot(); 
    }

    void ButtonJump_ButtonClick()
    {
        Controller.Jump();   
    }
		
	void Update () {
        if (Input.GetKey(KeyCode.D) || joystick.position.x >= Sensivity)
        {
            Controller.MoveHorizontal(joystick.position.x);
        }
        else if (Input.GetKey(KeyCode.A) || joystick.position.x <= -Sensivity)
        {
            Controller.MoveHorizontal(joystick.position.x);
        }
        else
            Controller.MoveHorizontal(0);
                     
            if (Input.GetKey(KeyCode.Space) )
            {
                Controller.Jump();               
            }

            if (Input.GetKey(KeyCode.LeftControl))
            {
                Controller.Shoot();                
            }
        
	}
}
